home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / utility / scrub.zip / SCRUB.C next >
C/C++ Source or Header  |  1992-01-08  |  1KB  |  58 lines

  1. #include <stdio.h>
  2.  
  3. void main (argc, argv)
  4. int argc;
  5. char *argv[];
  6. {
  7. FILE *text_in, *text_out;
  8. char ch, name[16];
  9. tmpnam(name);
  10.  
  11. if (argc < 3){
  12.    puts ("SCRUB removes the unwanted character from your file.\n\n");
  13.    puts ("Syntax: SCRUB <file> <ASCII code for char>\n\nPlease retry.\n");
  14.    exit(0);
  15. }
  16.  
  17. if (atoi (argv[2]) == 0){
  18.    puts ("You must enter an ASCII code other than 0.");
  19.    exit();
  20. }
  21.  
  22.  
  23. if (rename (argv[1], name) != 0){
  24.    perror ("rename");
  25. }
  26.  
  27. if ((text_in = fopen (name, "r")) == NULL){
  28.     puts ("Error opening file\n");
  29.     exit(0);
  30. }
  31.  
  32. if ((text_out = fopen (argv[1], "w"))==NULL){
  33.    puts ("Error opening outfile");
  34.    exit(0);
  35. }
  36.  
  37. while (!feof (text_in)){
  38.       ch=getc(text_in);
  39.       if (ch != atoi (argv[2])){                /* Is it NOT the char? */
  40.      putc (ch, text_out);                   /* If not, pass it out */
  41.       }
  42.       else{                                     /* Otherwise, output */
  43.       putc (' ', text_out);                     /* a SPACE */
  44.       }
  45. }
  46.  
  47. if (fclose(text_in)) puts ("Error closing infile\n");
  48. if (fclose(text_out)) puts ("Error closing tempfile\n");
  49.  
  50. if (unlink (name) != 0){
  51.    perror ("unlink");
  52. }
  53.  
  54. puts ("Done - thank you for using SCRUB!\n");
  55. exit(0);
  56. }
  57.  
  58.